<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <input type="file" name="" id="">
  <img src="" alt="">

  <script>
    const inp = document.querySelector('input')
    const img = document.querySelector('img')

    inp.onchange = function(e) {
      // 获取用户选择的图片
      // console.log(e.target.files[0])

      // 生成一个临时的预览地址  URL.createObjectURL(要预览的图片)
      // blob:null/5fed0b65-7804-4ae7-bf2c-6f4985e00969   经典的预览地址的格式
      const temp = URL.createObjectURL(e.target.files[0])
      console.log(temp)

      img.src = temp
    }
  </script>
</body>
</html>
